<?php

namespace common\models\shop;

use backend\modules\business\models\BusinessPig;
use common\models\business\BusinessUser;
use common\models\farmerhouse\FarmerhouseHouse;
use Yii;
use yii\db\Query;

/**
 * This is the model class for table "shop_house_order".
 *
 * @property string $id
 * @property string $ordersn
 * @property integer $userid
 * @property string $name
 * @property string $mobile
 * @property integer $houseid
 * @property string $price
 * @property integer $startdate
 * @property integer $enddate
 * @property integer $days
 * @property integer $roomnum
 * @property string $planin
 * @property integer $status
 * @property string $transid
 * @property integer $paytype
 * @property string $remark
 * @property integer $createtime
 */
class ShopHouseOrder extends \yii\db\ActiveRecord
{

    //-2支付失败  -1取消状态，0普通状态，1为已付款，2为待入住，3为已入住，4订单完结(已评价)
    const STATUS_PAYFAIL = -2;
    const STATUS_CANCAL = -1;
    const STATUS_MANAL = 0;
    const STATUS_PAY = 1;
    const STATUS_WAITLIVE = 2;
    const STATUS_CONFIRMLIVE = 3;
    const STATUS_FINISH = 4;
    public static $statues = [
        self::STATUS_PAYFAIL => '支付失败',
        self::STATUS_CANCAL => '取消',
        self::STATUS_MANAL => '待支付',
        self::STATUS_PAY => '已付款',
        self::STATUS_WAITLIVE => '待入住',
        self::STATUS_CONFIRMLIVE => '已入住',
        self::STATUS_FINISH => '已评价',
    ];

    const WECHAT_PAY = 1;
    const NO_PAY = 0;
    public static $paytype = [
        self::WECHAT_PAY => '微信支付',
        self::NO_PAY => '未支付',
    ];


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '农家乐订单',      //用于修改了什么的显示
        'mainfield' => 'ordersn',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shop_house_order';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userid', 'houseid', 'startdate', 'enddate', 'days', 'roomnum', 'planin', 'status', 'createtime'], 'required'],
            [['userid', 'houseid', 'startdate', 'enddate', 'days', 'roomnum', 'status', 'paytype', 'createtime','paytime'], 'integer'],
            [['price','cost'], 'number'],
            [['ordersn', 'name', 'mobile', 'transid', 'remark'], 'string', 'max' => 255],
            [['planin'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'ordersn' => '订单号',
            'userid' => '下单人id',
            'name' => '下单人',
            'mobile' => '手机',
            'houseid' => '农家乐id',
            'price' => '价格',
            'cost' => '实际消费',
            'startdate' => '入住日期',
            'enddate' => '离开日期',
            'days' => '入住天数',
            'roomnum' => '房间数',
            'planin' => '预计到达时间',
            'status' => '状态',
            'transid' => '支付流水号',
            'paytype' => '支付类型',
            'remark' => '备注',
            'createtime' => '创建时间',
            'paytime' => '付款时间',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     * 获取下单人
     */
    public function getUser()
    {
        return $this->hasOne(BusinessUser::className(),['id'=>'userid']);
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取仔猪信息
     */
    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取农家乐信息
     */
    public function getHouse()
    {
        return $this->hasOne(FarmerhouseHouse::className(),['id'=>'houseid']);
    }





}
